String myString = "1234";
int foo = Integer.parseInt(myString);

If you look at the Java Documentation you'll notice the "catch" is that this function can throw a NumberFormatException, which of course you have to handle:

int foo;
try {
   foo = Integer.parseInt(myString);
}
catch (NumberFormatException e)
{
   foo = 0;
}

(This treatment defaults a malformed number to 0, but you can do something else if you like.)

Alternatively, you can use an Ints method from the Guava library, which in combination with Java 8's Optional, makes for a powerful and concise way to convert a string into an int:

import com.google.common.primitives.Ints;

int foo = Optional.ofNullable(myString)
 .map(Ints::tryParse)
 .orElse(0)

Javaint转StringString转int 各方法效率对比_行者小朱的博客 ...

https://blog.csdn.net/u012050154/article/details/51320638

2016年5月5日 ... 一、int转String有三种方式(1)num + ""(2)String.valueOf(num)(3)Integer.toString( num)//int => Stringint num = 123456789;//(1)num + ""long start ...

Java Convert String to int - javatpoint

https://www.javatpoint.com/java-string-to-int

We can convert String to an int in java using Integer.parseInt() method. To convert String into Integer, we can use Integer.valueOf() method which returns ...

JAVAstringint 互相转化| 菜鸟教程

https://www.runoob.com/w3cnote/java-string-and-int-convert.html

2、 int i = Integer.valueOf(my_str).intValue();. 注: 字串成Double, Float, Long 的 方法大同小异. 2 如何将整数int 转换成字串String ?

Java String转换int_蜻蜓轩-CSDN博客

https://blog.csdn.net/Player26/article/details/3346936

2008年11月21日 ... String转换int型//convert str(String) to i(int)String str;int i = Integer.parseInt(str);int转换String//conver i(int) to str(String)int i;String str = i.

How do I convert a String to an int in Java? - Stack Overflow

https://stackoverflow.com/questions/5585779/how-do-i-convert-a-string-to-an-int-in-java

String mystr = mystr.replaceAll("[^\\d]", ""); int number = Integer.parseInt(mystr);.

StringInteger的相互转化_根号三-CSDN博客_string 转integer

https://blog.csdn.net/u011983531/article/details/50888139

2016年3月14日 ... 通过toString()方法,可以把整数(包括0)转化字符串,但是Integer如果是null 的话,就会报空指针异常。 2、String.valueOf(Object obj)可以把 ...

Java 如何将String转化Int_学亮编程手记-CSDN博客_java string转int

https://blog.csdn.net/a772304419/article/details/79723249

2018年3月28日 ...Java 中要将String 类型转化int 类型时,需要使用Integer 类中的 parseInt() 方法 或者 valueOf() 方法进行转换.例1:123456String str = "123"; ...

JavaString转int类型出现的问题及解决方式- 知乎

https://zhuanlan.zhihu.com/p/37402485

2018年5月28日 ... 一般在JavaString转Int主要有两种方法: Integer.parseInt(str); Integer.valueOf (str); ps:两者的不同之处: Integer.parseInt(s)返回值为Int ...

Java String to Int – How to Convert a String to an Integer

https://www.freecodecamp.org/news/java-string-to-int-how-to-convert-a-string-to-an-integer/

Nov 23, 2020 ... 1. Use Integer.parseInt() to Convert a String to an Integer. This method returns the string as a primitive type int. If the string does not ...

Java Convert String to int examples

https://beginnersbook.com/2013/12/how-to-convert-string-to-int-in-java/

1. Java – Convert String to int using Integer.parseInt(String) ... Here we have a String str with the value “1234”, the method parseInt() takes str as argument and ...

java String转int int转化String - 草木物语- 博客园

https://www.cnblogs.com/ooo0/p/9803595.html

2018年10月17日 ... String str = "123"; int a = Integer.parseInt(str); System.out.println(a); Integer b = Integer.valueOf(str); System.out.println(b); int c = Integer.

java-string转换integer的方式及原理- 简书

https://www.jianshu.com/p/9eebb4f2ccb1

2018年9月4日 ... 1 Integer.parseInt(String str)方法2 Integer.parseInt(String s, int radix)方法3 Character....

How to convert a Java String to an Int - JAXenter

https://jaxenter.com/convert-java-string-int-134101.html

May 17, 2017 ... Java String to int conversion. Overlooking the exception it can throw, use this: int i = Integer.parseInt(myString);. If the String signified by the ...

Java Convert String to Integer

https://stackabuse.com/java-convert-string-to-integer/

Converting String to Integer. For converting String to Integer or int, there are four built-in approaches. The wrapper class Integer provides a few methods ...

Different ways for Integer to String Conversions In Java ...

https://www.geeksforgeeks.org/different-ways-for-integer-to-string-conversions-in-java/

May 1, 2021 ... toString(int) or String.valueOf(int). But if your variable is already an instance of Integer (wrapper class of the primitive type int), it is better to just ...

How to convert an integer to a string in Java

https://www.educative.io/edpresso/how-to-convert-an-integer-to-a-string-in-java

1. The toString() method. This method is present in many Java classes. It returns a string. · 2. String.valueOf(). Pass your integer (as an int or Integer) to this method ...

How to convert a Java String to an Int | alvinalexander.com

https://alvinalexander.com/java/edu/qanda/pjqa00010.shtml

Feb 27, 2021 ... The most direct solution to convert a string to an integer in Java is to use the parseInt method of the Integer class. parseInt converts the String to ...

Accepted java String to Integer (atoi)

https://leetcode.com/problems/string-to-integer-atoi/

Read in next the characters until the next non-digit charcter or the end of the input is reached. The rest of the string is ignored. Convert these digits into an integer ...